package com.ruoyi.web.controller.community;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.community.domain.EcFoods;
import com.ruoyi.community.mapper.EcFoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/community/ec")
public class FoodController extends BaseController {
    @Autowired
    EcFoodsMapper ecFoodsMapper;

    @GetMapping("/foods")
    public TableDataInfo getFoodsByRestaurantId(EcFoods ecFoods){
        startPage();
//        List<EcFoods> list = ecFoodsMapper.selectFoodsByRestaurantId(ecFoods.getRestaurantId());
        List<EcFoods> list = ecFoodsMapper.selectEcFoodsList(ecFoods);
        return getDataTable(list);
    }

    @PostMapping("/food")
    public AjaxResult addFood(@RequestBody EcFoods ecFoods) {
        return toAjax(ecFoodsMapper.insert(ecFoods));
    }

    @PutMapping("/food")
    public AjaxResult updateFood(@RequestBody EcFoods ecFoods) {
        return toAjax(ecFoodsMapper.updateByPrimaryKey(ecFoods));
    }
}
